package com.zhengdongzulin.zuke.app.work.vm

import androidx.lifecycle.rxLifeScope
import com.lxj.androidktx.livedata.StateLiveData
import com.zhengdongzulin.zuke.app.Api
import com.zhengdongzulin.zuke.app.data.WorkListDetailBean
import com.zhengdongzulin.zuke.base.BaseViewModel
import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toResponse
import java.io.File

class ZKAddWorkVM : BaseViewModel() {
    var createSuccess: StateLiveData<WorkListDetailBean> = StateLiveData()

    /**
     * incidentType
    String	是	事件性质：维修工单、报事工单、服务申请
    title
    String	是	标题：报修、保洁申请、空调申请【在对应的事件性质下选择】
    linkmanName
    String	是	联系人名称
    linkmanPhone
    String	是	联系人电话
    description
    String	是	描述
     */
    fun create_gong_dan(
        incidentType: String,
        title: String,
        linkmanName: String,
        linkmanPhone: String,
        description: String,
        userId: String = "4612",
        imgList: ArrayList<File>
    ) {
        rxLifeScope.launch(
            {
                var r = RxHttp.postForm(Api.CREATE_GONG_DAN)
                    .add("incidentType", incidentType)
                    .add("title", title)
                    .add("linkmanName", linkmanName)
                    .add("linkmanPhone", linkmanPhone)
                    .add("description", description)
                    .add("userId", userId)
                    .addFiles("imgList", imgList)
                    .toResponse<WorkListDetailBean>()
                    .await()
                createSuccess.postValueAndSuccess(r)
            }, {
                assignment(it, createSuccess)
            }
        )
    }
}